<!-- 商家入驻 -->
<template>
	<view class="seller">
		<bottomSeller ref="boottomPopus" @showPicker="showPicker" @getSubmit="getSubmit"></bottomSeller>
		<picker-area v-if="show" @getAddress="getAddress"></picker-area>
	</view>
</template>
<script>
	import bottomSeller from 'pages/user/components/bottom-seller/bottom-seller.vue'
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
    import mixins from '@/common/mixins.js';
	export default {
        mixins:[mixins],
		components: {
			bottomSeller
		},
		data() {
			return {
				after_sale: this.imgUrl + 'after_sale-add.png',
				rule: {
					name: {
						type: "form_data",
						rules: [{
							rule: /^s*$/,
							v_res: false,
							message: "请输入店铺名称",
						}, ],
					},
					shop_category_id: {
						type: "form_data",
						rules: [{
							rule: /^s*$/,
							v_res: false,
							message: "请输入店铺分类",
						}, ],
					},
					tel: {
						type: "form_data",
						rules: [{
							rule: /^s*$/,
							v_res: false,
							message: "请输入电话",
						}, ],
					},
					mobile: {
						type: "form_data",
						rules: [{
								rule: /^s*$/,
								v_res: false,
								message: "请填写手机号",
							}, {
								rule: /^[1][3-9][0-9]{9}$/,
								v_res: true,
								message: "请填写正确的手机号码",
							},
					
						],
					},
					address: {
						type: "form_data",
						rules: [{
							rule: /^s*$/,
							v_res: false,
							message: "请选择地址",
						}, ],
					},
					place: {
						type: "form_data",
						rules: [{
							rule: /^s*$/,
							v_res: false,
							message: "请选择详细地址",
						}, ],
					},
				},
				obj: {        // 提交信息
					member_id: 1,
					name: '1',
					shop_category_id: 1,
					mobile: '18006966027',
					tel: '18006966027',
					address: '',
					lat: 24.881627,
					lng: 118.628881
				},
				address: '',   // 地址
				key: "4c68ea9aeac446dfae048ef70dfa8b09",//高德地图web服务的key，不是微信小程序的key
				url: "https://restapi.amap.com/v3/geocode/geo?parameters"   // 高德地图接口地址
			};
		},
		computed: {
			...mapState({
				info: state => state.address.info
			}),
		},
		methods: {
			getSubmit(val) {
				let status = this.$tools.verification(val, this.rule)
				if(!status.status) return;
				this.obj.name = val.name
				this.obj.mobile = val.mobile
				this.obj.tel = val.tel
				this.obj.shop_category_id = Number(val.shop_category_id)
				let str = val.address.concat(val.place)
				this.obj.address = str
				uni.request({
					url: this.url,
					method: 'GET',
					data: {
						key: this.key,
						address: this.obj.address
					},
					success: (res) => {
						// 获取经纬度
						let data = res.data.geocodes[0].location;
						// 分隔经纬度
						let lng = data.split(',')[0];
						let lat = data.split(',')[1];
						this.obj.lng = Number(lng)
						this.obj.lat = Number(lat)
						// 获取地址的标记地点
					}
				})
				setTimeout(() => {
					this.$api('memberapplyShop',this.obj).then(res => {
						if(res.status) {
							this.$tools.toast('申请商家入驻成功')
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
							},1000)
						}
					})
				},1000)
			},
		}
	};
</script>

<style lang="scss" scoped>
	@import './index.scss';
</style>
